home *** CD-ROM | disk | FTP | other *** search
/ Hyper Stacks 1994 May / Hyper Stacks (Pacific HiTech)(1994)[Mac].iso / HyperTalk / RegionPackage / BitMapToRegion ƒ / BMTR Patcher.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-10  |  2.9 KB  |  159 lines  |  [TEXT/KAHL]

  1. /* Multi-purpose BMTR Installer
  2.  
  3.    Written by Nigel Perry, 1990. This is in the PUBLIC DOMAIN.
  4.    
  5.    Define INIT to use the source in the BMTR Init π.
  6.    Define XCMD for the BMTR XCMD π.
  7.    Define neither for the BMTR Patcher π.
  8.    
  9.    CHECK the defines before compiling, there is only ONE
  10.    copy of this source file. The projects that use it have
  11.    different project types and different π.rsrc files.
  12.    
  13.  */
  14.  
  15. /*#define INIT*/    /* compile as INIT */
  16. #define XCMD    /* compile as XCMD */
  17.  
  18. #ifdef XCMD
  19. #include <HyperXCmd.h>
  20.  
  21. /* from LSC 2.01 supplement */
  22. #define SetUpA4()        asm \
  23.                             {  move.l    a4,-(sp) \
  24.                                move.l    a0,a4 \
  25.                             }
  26. #define RestoreA4()    asm { move.l (sp)+,a4 }
  27.  
  28. #endif
  29.  
  30. #define _BitMapToRegion                 0xA8D7
  31. #define _Unimplemented                    0xA89F
  32.  
  33. #define NIL ((void *)0)
  34. #define EMPTY ((char *)0xA02)        /* low memory global OneOne */
  35.                                     /* used for "" and "\p" */
  36.  
  37. /* struct to match patch header */
  38. typedef struct
  39. {    int        bra_instr;
  40.     long    check1, check2;
  41. } cheader;
  42.  
  43. #ifdef XCMD
  44. pascal main(paramPtr) XCmdPtr paramPtr;
  45. #else
  46. main()
  47. #endif
  48. {    register Ptr UNIMPLaddr;
  49.     register cheader *patch, **hp;
  50. #ifdef XCMD
  51.     Handle h;
  52.     register long ans;
  53. #else
  54. #ifndef INIT
  55.     /* patcher */
  56.     Str255 msg;
  57.     register msgnum;
  58. #endif
  59. #endif
  60.     
  61. #ifdef XCMD
  62.     SetUpA4();
  63. #else
  64. #ifndef INIT
  65.     /* patcher, use only in Finder */
  66.     InitGraf(&thePort);
  67.     InitFonts();
  68.     FlushEvents(everyEvent,0);
  69.     InitWindows();
  70.     InitMenus();
  71.     TEInit();
  72.     InitDialogs(NIL);
  73.     InitCursor();
  74.     
  75.     if( CautionAlert(2, NIL) == 1 ) return;
  76. #endif
  77. #endif    
  78.     asm
  79.     {    move.w    #_Unimplemented,d0
  80.         _GetTrapAddress
  81.         move.l    a0,UNIMPLaddr
  82.         move.w    #_BitMapToRegion,d0
  83.         _GetTrapAddress    NEWTOOL
  84.         cmp.l    a0,UNIMPLaddr
  85. #ifdef INIT
  86.         bne.s    @systemTrap
  87. #else
  88.         beq.s    @patchit
  89.         cmp.l    #'np90',OFFSET(cheader,check1)(a0)
  90.         bne.s    @systemTrap
  91.         cmp.l    #'juri',OFFSET(cheader,check2)(a0)
  92.         bne.s    @systemTrap
  93. #ifndef XCMD
  94.         ; our trap - remove it
  95.         _RecoverHandle    SYS
  96.         _DisposHandle
  97.         move.l    UNIMPLaddr,a0
  98.         move.w    #_BitMapToRegion,d0
  99.         _SetTrapAddress    NEWTOOL
  100.         moveq    #2,msgnum
  101. #else
  102.         move.l    #'woz\0',ans
  103. #endif
  104.         bra.s    @display
  105.     patchit:
  106. #endif
  107.     }
  108.  
  109.     hp = (cheader **)GetNamedResource('TRAP', "\pBitMapToRegion");
  110.     DetachResource((Handle)hp);
  111.     
  112.     asm
  113.     {    move.l    hp,a0
  114.         _MoveHHi        ; move to top of heap
  115.         _HLock            ; and lock it down
  116.         ; SetTrapAddress(_BitMapToRegion, StripAddress(*hp))
  117.         move.l    (a0),d0
  118.         _StripAddress
  119.         move.l    d0,a0
  120.         move.w    #_BitMapToRegion,d0
  121.         _SetTrapAddress    NEWTOOL
  122. #ifndef INIT
  123. #ifdef XCMD
  124.         move.l    #'add\0',ans
  125. #else
  126.         moveq    #1,msgnum
  127. #endif
  128.         bra.s    @display
  129. #endif
  130.     }
  131.  
  132. systemTrap:
  133. #ifdef XCMD
  134.     ans = 'sys\0';
  135. display:
  136.     asm
  137.     {    moveq    #4,d0
  138.         _NewHandle
  139.         move.l    a0,h
  140.         move.l    (a0),a0
  141.         move.l    ans,(a0)
  142.     }
  143.     paramPtr->returnValue = h;
  144. #else
  145. #ifndef INIT
  146.     msgnum = 3;
  147. display:
  148.     GetIndString(msg, 1, msgnum);
  149.     ParamText(msg, EMPTY, EMPTY, EMPTY);
  150.     NoteAlert(1, NIL);
  151. #else
  152.     ;    /* INIT -> something must come after systemTrap label */
  153. #endif
  154. #endif
  155.  
  156. #ifdef XCMD
  157.     RestoreA4();
  158. #endif
  159. }